using UnityEngine;
using Math;

public class FirstPersonController : MonoBehaviour
{
    public float LookSpeed = 2.0f;
    public float MoveSpeed = 0.2f;

    public float RotationX = 90.0f;
    public float RotationY = 0.0f;

    public float XMinLimit = -90.0f;
    public float XMaxLimit = 90.0f;

    void Start()
    {
        transform.rotation = Quaternion.Euler(RotationX, RotationY, 0.0f);
    }

    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            RotationX -= Input.GetAxisRaw("Mouse Y") * LookSpeed;
            RotationY += Input.GetAxisRaw("Mouse X") * LookSpeed;
            RotationX = Maths.ClampAngle(RotationX, XMinLimit, XMaxLimit);

            transform.rotation = Quaternion.Euler(0.0f, RotationY, 0.0f) * Quaternion.Euler(RotationX, 0.0f, 0.0f);
        }
        transform.position += Input.GetAxisRaw("Vertical") * transform.forward * MoveSpeed;
        transform.position += Input.GetAxisRaw("Horizontal") * transform.right * MoveSpeed;
    }
}